package com.yuchuang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuchuang.base.PageInfo;
import com.yuchuang.mapper.BrandMapper;
import com.yuchuang.model.Brand;
import com.yuchuang.model.vo.BrandVo;
import com.yuchuang.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @Author:cy Date: 2023-06-16-13:14
 * Description:
 */
@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements BrandService {
    @Autowired
    private BrandMapper brandMapper;
    @Override
    public List<Brand> queryAll(HttpServletRequest request){
        QueryWrapper<Brand> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(request.getParameter("brandName") != null,"brand_name",request.getParameter("brandName"));
        List<Brand> list = brandMapper.queryAllImplBatis(queryWrapper);
        return list;
    }
    @Override
    public PageInfo selectPageVo(BrandVo brandVo){
        Page<Brand> page = new Page<>(brandVo.getPageNum(),brandVo.getPageSize());
        QueryWrapper<Brand> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(brandVo.getBrandName() != null,"brand_name",brandVo.getBrandName());
        IPage<Brand> result = brandMapper.selectPageVoMapper(page,queryWrapper);
        int pageNums =(int) result.getPages();
        int size =(int) result.getSize();
        int pageNum =(int) result.getCurrent();
        int total =(int) result.getTotal();
        List t = result.getRecords();
        return new PageInfo().setContent(t).setPage(pageNum).setSize(size).setTotal(total).setPages(pageNums);
    }
    @Override
    public int insert(Brand brand){
        int val = brandMapper.insertImplBatis(brand);
        return val;
    }
    @Override
    public int update(Map<String,Object> params){
        int val = brandMapper.updateImplBatis(params);
        return val;
    }
    @Override
    public int delete(Map<String,Object> params){
        int val = brandMapper.deleteImplBatis(params);
        return val;
    }
}
